home *** CD-ROM | disk | FTP | other *** search
/ HamCall (April 1991) / HAMCALL CD-ROM (Buckmaster)(April 1991).BIN / prgming / ctutor / struct3.c < prev    next >
Text File  |  1990-10-14  |  1KB  |  48 lines

  1.                                          /* Chapter 11 - Program 3 */
  2. main()
  3. {
  4. struct {
  5.    char initial;
  6.    int age;
  7.    int grade;
  8.    } kids[12],*point,extra;
  9.  
  10. int index;
  11.  
  12.    for (index = 0;index < 12;index++) {
  13.       point = kids + index;
  14.       point->initial = 'A' + index;
  15.       point->age = 16;
  16.       point->grade = 84;
  17.    }
  18.  
  19.    kids[3].age = kids[5].age = 17;
  20.    kids[2].grade = kids[6].grade = 92;
  21.    kids[4].grade = 57;
  22.  
  23.    for (index = 0;index < 12;index++) {
  24.       point = kids + index;
  25.       printf("%c is %d years old and got a grade of %d\n",
  26.              (*point).initial, kids[index].age,
  27.              point->grade);
  28.    }
  29.    extra = kids[2];               /* Structure assignment */
  30.    extra = *point;                /* Structure assignment */
  31. }
  32. /* Result of execution
  33.  
  34. A is 16 years old and got a grade of 84
  35. B is 16 years old and got a grade of 84
  36. C is 16 years old and got a grade of 92
  37. D is 17 years old and got a grade of 84
  38. E is 16 years old and got a grade of 57
  39. F is 17 years old and got a grade of 84
  40. G is 16 years old and got a grade of 92
  41. H is 16 years old and got a grade of 84
  42. I is 16 years old and got a grade of 84
  43. J is 16 years old and got a grade of 84
  44. K is 16 years old and got a grade of 84
  45. L is 16 years old and got a grade of 84
  46.  
  47. */
  48.